package edu.example.student.dao;

import edu.example.student.beans.Building;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

public class BuildingDao {
    public List<Building> findAll()
    {
        DataSource dataSource=C3p0Utils.getDataSource();
        QueryRunner queryRunner=new QueryRunner(dataSource);
        String sql="select * from buildings";
        BeanListHandler beanListHandler=new BeanListHandler(Building.class);
        List<Building> list=null;
        try {
            list= (List<Building>) queryRunner.query(sql,beanListHandler);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
}
